package com.wst.wst_server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wst.wst_server.entity.Org;
import com.wst.wst_server.entity.Section;
import com.wst.wst_server.service.ISectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 科室信息 前端控制器
 * </p>
 *
 * @author zyk
 * @since 2023-03-24
 */
@RestController
@RequestMapping("/section")
public class SectionController {

    @Autowired
    ISectionService service;

    @RequestMapping("/getallsection")
    public ResponseResult<List<Section>> getsection(){
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.select("DISTINCT divName","id");
        return new ResponseResult<List<Section>>(200,"ok",service.list(queryWrapper));
    }

    @RequestMapping("/getsectionorgid")
    public ResponseResult<List<Section>> getallsection(Integer orgId){
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.eq("orgId",orgId);
        return new ResponseResult<List<Section>>(200,"ok",service.list(queryWrapper));
    }

    @RequestMapping("/add")
    public ResponseResult add1(Section section){
        return new ResponseResult(200,"ok",service.save(section));
    }

    @RequestMapping("/getorgandsection")
    public ResponseResult<IPage<Map<String ,Object>>> getorgandsection(@RequestParam Map<String ,Object> map){
        return new ResponseResult<IPage<Map<String ,Object>>>(200,"ok",service.getorgandsection(map));
    }

    @RequestMapping("/getbyorgidanddivname")
    public ResponseResult<IPage<Map<String, Object>>> getbyorgidanddivname(@RequestParam Map<String,Object> map){
        return new ResponseResult<IPage<Map<String, Object>>>(200,"ok",service.getbyorgidanddivname(map));
    }

    @RequestMapping("/getupdate")
    public ResponseResult upadte(Section section){
        return new ResponseResult(200,"ok",service.saveOrUpdate(section));
    }

    @RequestMapping("/getbyid")
    public ResponseResult<Section> getbyid(Integer id){
        return new ResponseResult<Section>(200,"ok",service.getById(id));
    }

    @RequestMapping("/deletebyid")
    public ResponseResult getbydeleteid(Integer id){
        return new ResponseResult(200,"ok",service.removeById(id));
    }
}
